using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using WroxGallery.Actions;
using WroxGallery.Models;
using WroxGallery.Models.Interfaces;

namespace WroxGallery.Controllers
{
    public class AdminController : Controller
    {
        private IConfigurationRepository _repository;
        public AdminController(IConfigurationRepository repository)
        {
            _repository = repository;
        }

        [TitleFilter("Admin")]
        public ActionResult Index()
        {
            GalleryConfiguration config = _repository.Config;
            return View(config);
        }

        [TitleFilter("Admin")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(
            [Bind(Prefix = "")]
            GalleryConfiguration config)
        {
            if (ViewData.ModelState.IsValid)
            {
                _repository.Config = config;
                _repository.Store();
                return RedirectToAction("Index");
            }

            return View();
        }
    }
}
